#ifndef _PHY_STRUCT_H
#define _PHY_STRUCT_H (1)

#include "crc32_sb.h"
#include "PhyConstants.h"

typedef enum HS_PhyStrTh{

    PHY_RX_INIT_TH=1, //1
    PHY_RX_DETECT_ENERGY_TH, //2
    PHY_RX_CLIP_DETECTION_TH, //3
    PHY_RX_JUNK_AGC_TRANSIENT_TH, //4
    PHY_RX_COARSE_SYNC_BUF_SYMB_TH, //5
    PHY_RX_COARSE_SYNC_CORR_TH, //6
    PHY_RX_GET_SYMBOL, //7
    PHY_RX_EST_CARRIER_ERR_TH, //8
    PHY_RX_SYMBOL_LOCK_TH, //9
    PHY_RX_SYMBOL_LOCK_ROTOR_TH, //10
    PHY_RX_SYMBOL_LOCK_CORR_TH, //11
    PHY_RX_SYMBOL_LOCK_FIND_MAX_TH, //12
    PHY_RX_SYMBOL_LOCK_CMFTAPS_TH, //13
    PHY_RX_STATE_SFD_TH, //14
    PHY_RX_STATE_HEADER_TH, //15
    PHY_STATE_DM_ONEMBPS_TH, //16
    PHY_STATE_DM_TWOMBPS_TH, //17
    PHY_STATE_DM_FIVEDOTFIVE_TH, //18
    PHY_STATE_DM_ELEVENMBPS_TH, //19
    PHY_STATE_TX_INIT_TH,  //20
    PHY_STATE_TX_SEND_PREAMBLE_TH, //21
    PHY_STATE_TX_SEND_SFD_TH, //22
    PHY_STATE_TX_SEND_HEADER_TH, //23
    PHY_STATE_TX_SEND_PAYLOAD_1MBPS_TH,  //24
    PHY_STATE_TX_SEND_PAYLOAD_2MBPS_TH, //25
    PHY_STATE_TX_SEND_PAYLOAD_5DOT5MBPS_TH, //26
    PHY_STATE_TX_SEND_PAYLOAD_11MBPS_TH, //27
    PHY_STATE_SWITCH_OFF_TH  //28

}ePHYSTATES_TH;

struct HS_Phy11bStr{

    volatile hs_uint32_t *rx_status_l;

	hs_int16_t sincos_t[64];

    volatile hs_int32_t cck_toggle_th2;
    volatile hs_int32_t cck_toggle_th3;
    volatile hs_int32_t outbuff_toggle_th1;
    volatile hs_int32_t outbuff_toggle_th2;
    volatile hs_int32_t eqoutbuff_toggle_th2;
    volatile hs_int32_t eqoutbuff_toggle_th3;

    hs_int32_t data_decoding;
    hs_int32_t freq_offset;
    hs_int16_t *iq_scale;
    hs_int16_t *iq_bias;

    hs_int16_t preamble_buffI[PREAMBLESYNCSIZE];
    hs_int16_t preamble_buffQ[PREAMBLESYNCSIZE];

    /* Data Mode Varaibles*/
	volatile hs_int16_t  ssRxSymbOldI;
	volatile hs_int16_t  ssRxSymbOldQ;
    volatile hs_uint8_t  ucDescrState;
    hs_uint8_t * volatile pcPayloadByte;

    hs_int32_t preamble_syncbit_pos;

        /** Header **/
	hs_uint8_t  ucDataRate;
    hs_int32_t  siLengthExt;
    hs_uint32_t uiNPayloadBytes;

    volatile hs_int32_t  e_detected;
    volatile hs_int32_t  ePhyState;
    volatile hs_int32_t  siNPayloadSym;
    volatile hs_int32_t  siRotorTableCounter;
    volatile hs_int32_t  siPhaseUpdate;

    /* Agc Variables */
    hs_int16_t	 agcIndex;
    hs_int32_t   siClipFlag;

	hs_int32_t   siReadPtr;

    /*Carrier Error Estimation Variables*/
    hs_int32_t   siAvgDiffSymbI;
    hs_int32_t   siAvgDiffSymbQ;

    volatile hs_int32_t eq_in_index;
    volatile hs_int16_t eq_energy;
    volatile hs_int32_t eq_count;

    /** Circular buffer Variables **/
    hs_int16_t   * piRdPtrI;
    hs_int16_t   * piStartPtrI;
    hs_int16_t   * piEndPtrI;
    hs_int16_t   * piRdPtrQ;
    hs_int16_t   * piStartPtrQ;
    hs_int16_t   * piEndPtrQ;
};

extern  struct HS_Phy11bStr  HS_Phy11bPtrGlobal;


/* Tx structure */

struct HS_PhyTx11bStr{

  volatile hs_uint32_t tx_status_l;
  volatile hs_int32_t  ePhyState;

  hs_uint8_t *crc_shared;
  hs_uint8_t *ucInputBit_shared_2_55;
  hs_uint8_t *ucInputBit_shared_11;
  hs_uint32_t *uiTempReg_shared;

  hs_int32_t subbuff_toggle;
  hs_int32_t symbol_count;
  hs_int16_t *HeaderSamplesI;
  hs_int16_t *HeaderSamplesQ;
  hs_int16_t *ShortHeaderSamplesI;
  hs_int16_t *ShortHeaderSamplesQ;

  hs_int32_t header_iq_offset;

  volatile hs_int32_t preamble_type;
  volatile hs_int32_t plcp_preamble_bits;
  volatile hs_uint8_t *psPayloadByte;
  volatile hs_uint16_t usDateRate;
  volatile hs_uint16_t usLength;

  hs_uint8_t ucScramState;
  hs_uint16_t ucPrevSymb;
  hs_uint16_t usSFD;

  hs_uint8_t  ucHeaderByte[6];

  hs_int16_t * psTxDtoABufferI;
  hs_int16_t * psTxDtoABufferQ;
  hs_int16_t * psTxDtoAStartI;
  hs_int16_t * psTxDtoAStartQ;
  hs_int16_t * psTxDtoAEndI;
};


enum {
	TX_MODE=1,
	RX_MODE
};

#endif

